{-----------------------------------------------------------------------------
 Unit Name: Controller
 Purpose:   Singleton Beispiel

 Author:    Nikolay Nenov
 Date:      13-04-2011
 History:
-----------------------------------------------------------------------------}
unit Controller;

interface

uses
  Windows, Messages, SysUtils, StrUtils, Variants, Classes, Dialogs;

type
  TController=Class
  private
    FID     : Integer;
    FParam  : String;
    constructor Create;
  public
    destructor Destroy; override;
    class function GetInstance : TController;
End;

implementation

var
  G_Controller: TController;


{-----------------------------------------------------------------------------
  Function:  GetInstance
  Arguments:
  Result:    TController

  Author:    Nikolay Nenov
  Date:      13-04-2011
-----------------------------------------------------------------------------}
class function TController.GetInstance: TController;
begin
  if G_Controller = nil then
    G_Controller := TController.Create;
  Result := G_Controller;
end;


{-----------------------------------------------------------------------------
  Procedure: Create
  Arguments:
  Author:    Nikolay Nenov
  Date:      13-04-2011
-----------------------------------------------------------------------------}
constructor TController.Create;
begin
  inherited Create;
  FID    := 123456;
  FParam := 'Param 1';
end;


{-----------------------------------------------------------------------------
  Procedure: Destroy
  Arguments:
  Author:    Nikolay Nenov
  Date:      13-04-2011
-----------------------------------------------------------------------------}
destructor TController.Destroy;
begin
  if G_Controller = Self then
    G_Controller := nil;

  inherited Destroy;
end;

end.

